import { ILoadMapTypeAll, ISearchTranslateAll } from '@/common';
import { getBaseUrl } from '@/services/urlconst';
import { getTenantID, getUserID, requestFunComponFiex } from '@/utils';
import { useRequest } from 'umi';

const baseUrl = getBaseUrl();

/**
 * 获取详情
 * @param callback  获取详情回调
 * @returns
 */
const getMcontractByIDService = (callback: (res: any) => void) => {
  /**  需要获取的数据字典 */
  const loadMdicIds: string[] = [
    `${getTenantID()}${ILoadMapTypeAll.PURCHASE_CATEGORY}`, //采购类别
    `${getTenantID()}${ILoadMapTypeAll.CONTRACT_TYPE}`, //采购类型
    `${getTenantID()}${ILoadMapTypeAll.PURCHASE_METHOD}`, //采购方式
    `${getTenantID()}${ILoadMapTypeAll.CONTRACT_STATE}`, //合同状态
    `${getTenantID()}${ILoadMapTypeAll.PAYMENT_STYLE}`, //支付方式
    `${getTenantID()}${ILoadMapTypeAll.COMPANY_TAXRATE}`, //税率
    `${getTenantID()}${ILoadMapTypeAll.CONTRACT_FIELDTYPE}`, //合同附件类型
    `${getTenantID()}${ILoadMapTypeAll.MATERIAL_MIDI}`, //量化单位
    `${getTenantID()}${ILoadMapTypeAll.ALLORDER_TYPE}`, //工单类型
  ];

  const getMcontractByID = useRequest(
    (params: any) => {
      let personUrl = `${baseUrl}/contractController/getMcontractByID`;
      const payload: Record<string, any> = {
        ...params,
        dicTypeIds: loadMdicIds?.toString(),
        dicTransName: 'state,supplyKind,supplyType,procureReal,payStyle,businessType,checkState,orderType',
        orgTransName: `${ISearchTranslateAll.CREATER_DEPT},${ISearchTranslateAll.OWNER_DEPT},${ISearchTranslateAll.CANCEL_DEPT},${ISearchTranslateAll.DUTY_DEPT}`,
        currentUserID: getUserID(),
      };
      return requestFunComponFiex('PUT', personUrl, payload);
    },
    {
      manual: true,
      onSuccess: callback,
    },
  );

  return {
    getMcontractByIDRun: getMcontractByID?.run,
    getMcontractByIDLoading: getMcontractByID?.loading,
    getMcontractByIDInfo: getMcontractByID?.data?.obj,
  };
};

export { getMcontractByIDService };
